/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.util;

/**
 *
 * @author amochakr
 */
public class Console {

    public static final byte TYPE_DEBUG = 0; // message types
    public static final byte TYPE_ERROR = 1;

    public static boolean debug = false; // print debugging messages

    private static final String SPACE    = " "; // for formatting
    private static final String SOFT_TAB = "     "; // for formatting

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static void message ( String message ) {
        System.out.println ( "[CRAWL]" + SPACE + message );
    } // end function message

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static void debug ( String function, String message ) {

        if ( debug ) {
            message ( makeMessage ( TYPE_DEBUG, function, message ) );
        }

    } // end function debug

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static void error ( String function, String message ) {
        message ( makeMessage ( TYPE_ERROR, function, message ) );
    } // end function error
    
    //--------------------------------------------------------------------------
    /** Javadoc here */
    private static String makeMessage (
                                byte type,
                                String function,
                                String message
                             )
    {
        StringBuffer buffer = new StringBuffer ();

        buffer = buffer.append ( SOFT_TAB );

        buffer = buffer.append (
                            (type == TYPE_DEBUG) ? "[Debug]" : "** [ERROR]"
                        );

        buffer = buffer.append (SPACE);

        if ( function != null ) {

            buffer = buffer.append ( "{" );
            buffer = buffer.append ( function );
            buffer = buffer.append ( "}" );
            buffer = buffer.append ( SPACE );
            buffer = buffer.append ( ":" );
            buffer = buffer.append ( SPACE );
        }

        buffer = buffer.append ( message );

        return buffer.toString();

    } // end method makeMessage

} // end class Console
